#pragma once

#include "leveldb/status.h"
#include "leveldb/slice.h"
#include "Stream.h"

class Reader {
public:
	Reader(Stream * stream, uint64_t startSequenceNumber = 0);
	~Reader();
	leveldb::Status open() ;
	leveldb::Status close();

	bool hasNext() const ;
	void next() ;

	std::pair<uint64_t, const leveldb::Slice> current() ;

	const uint64_t sequenceNumber() const  { return sequenceNumber_; }

private:
    std::pair<uint64_t, const leveldb::Slice> _current();
    leveldb::Status recover();
	
private:
	Stream * stream_ = nullptr;
    uint64_t sequenceNumber_ = 0;
	bool isOpen_ = false;
    Stream::InternalReader * reader_ = nullptr;
    uint64_t startSequenceNumber_;
};
